#pragma once
#include "Thread.h"
#include "Semaphore.h"

#include <iostream>
using namespace std;

class Job
{
public:
    enum Status
    {
        IDLE = 0,
        BUSY
    };

    Job(void) : m_sem(1)
    {
         m_nId = -1;
         m_pData = NULL;
         m_status = IDLE;
         m_pThread = NULL;
    }
    Job(void* pData) : m_sem(1)
    {
         m_nId = -1;
         m_pData = pData;
         m_status = IDLE;
         m_pThread = NULL;
    }

    virtual ~Job(void) {}

    int GetId();
    void SetId(int nId);

    void* GetData();
    void SetData(void* pData);

    Status GetStatus();
    void SetStatus(Status status);

    bool IsDone();
    void SetDone(bool bDone);

    Thread* GetWorkThread();
    void SetWorkThread(Thread* pThread);

    virtual void Run(void* ptr) = 0;
    virtual void Destory() {};

protected:
    int         m_nId;
    void*       m_pData;
    Status      m_status;
    bool        m_bDone;
    Thread*     m_pThread; //The thread associated with the job
    Semaphore   m_sem;
};

